package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.ShiroUtils;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.config.domain.EcardDeptPackageOrg;
import com.xydtech.ecard.config.service.IEcardDeptPackageOrgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 包保配置Controller
 *
 * @author JHON
 * @date 2022-07-22
 */
@Controller
@RequestMapping("/config/deptPackageOrg")
public class EcardDeptPackageOrgController extends BaseController {
    private String prefix = "ecard/config/deptPackageOrg";

    @Autowired
    private IEcardDeptPackageOrgService ecardDeptPackageOrgService;

    @RequiresPermissions("ecardConfig:deptPackageOrg:view")
    @GetMapping()
    public String deptPackageOrg() {
        return prefix + "/deptPackageOrg";
    }

    /**
     * 查询包保配置列表
     */
    @RequiresPermissions("ecardConfig:deptPackageOrg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardDeptPackageOrg ecardDeptPackageOrg) {
        if (ecardDeptPackageOrg.getDeptId() == null) {
            ecardDeptPackageOrg.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        startPage();
        List<EcardDeptPackageOrg> list = ecardDeptPackageOrgService.selectEcardDeptPackageOrgList(ecardDeptPackageOrg);
        return getDataTable(list);
    }

    /**
     * 导出包保配置列表
     */
    @RequiresPermissions("ecardConfig:deptPackageOrg:export")
    @Log(title = "包保配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardDeptPackageOrg ecardDeptPackageOrg) {
        List<EcardDeptPackageOrg> list = ecardDeptPackageOrgService.selectEcardDeptPackageOrgList(ecardDeptPackageOrg);
        ExcelUtil<EcardDeptPackageOrg> util = new ExcelUtil<EcardDeptPackageOrg>(EcardDeptPackageOrg.class);
        return util.exportExcel(list, "包保配置数据");
    }

    /**
     * 新增包保配置
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存包保配置
     */
    @RequiresPermissions("ecardConfig:deptPackageOrg:add")
    @Log(title = "包保配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardDeptPackageOrg ecardDeptPackageOrg) {
        return toAjax(ecardDeptPackageOrgService.insertEcardDeptPackageOrg(ecardDeptPackageOrg));
    }

    /**
     * 修改包保配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        EcardDeptPackageOrg ecardDeptPackageOrg = ecardDeptPackageOrgService.selectEcardDeptPackageOrgById(id);
        mmap.put("ecardDeptPackageOrg", ecardDeptPackageOrg);
        return prefix + "/edit";
    }

    /**
     * 修改保存包保配置
     */
    @RequiresPermissions("ecardConfig:deptPackageOrg:edit")
    @Log(title = "包保配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardDeptPackageOrg ecardDeptPackageOrg) {
        return toAjax(ecardDeptPackageOrgService.updateEcardDeptPackageOrg(ecardDeptPackageOrg));
    }

    /**
     * 删除包保配置
     */
    @RequiresPermissions("ecardConfig:deptPackageOrg:remove")
    @Log(title = "包保配置", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ecardDeptPackageOrgService.deleteEcardDeptPackageOrgByIds(ids));
    }
}
